<?php
$caption = BUtils::T('register_lbl');
$this->pageTitle = $caption;

//make categories for merchants
$categories = MerchantObject::Categories();
$all_areas_fi = MerchantObject::BusinessAreas();
$cities_fi = array_keys($all_areas_fi);
?>
<div class="row-fluid">
	<div class="span12">
		<div class="login-container">
			<div class="space-6" style="margin-top:48px;"></div>
			<div class="center">
				<h1>
					<span class="blue">Yamii</span>
					<span class="blue">for Business</span>
				</h1>
				<h4 class="red"><?php echo BUtils::T('yb_brief'); ?></h4>
			</div>
			<div class="space-6"></div>
<div class="row-fluid">
	<div class="box_white span12">
		<div class="biz-form">
			<div class="margin">
				<div class="pull-right">
					<?php BHelper::HtmlLanguageButtons(); ?>
				</div>
				<h3 class="header blue lighter bigger">
					<i class="icon-cloud blue"></i> <?php echo $caption; ?>
				</h3>
				<div class="clearfix"></div>
			</div>
<?php
if(Yii::app()->user->hasFlash('contact')) {
	echo '<div class="fieldswrap"><div class="fields"><h3>';
	echo Yii::app()->user->getFlash('contact');
	echo '</h3></div><div class="margin actions">';
	echo CHtml::link('<span>'.BUtils::T('have_account_already_lbl').'</span>', Yii::app()->user->loginUrl, array('class' => 'button button-huge button-thin button-compliment'));
	echo '</div></div>';
} else {
	$form=$this->beginWidget('CActiveForm', array(
		'id'=>'contact-form',
		'enableClientValidation'=>true,
		'clientOptions'=>array(
			'validateOnSubmit'=>true,
		),
	));
?>
<div class="fieldswrap">
<div class="fields">
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'company_name'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'company_name', array('class'=>'span12')); ?>
			<?php echo $form->error($model,'company_name'); ?>
		</div>
	</div>
	<div class="block row-fluid">
		<div class="span7">
			<div class="lbl"><?php echo $form->labelEx($model,'first_name'); ?></div>
			<div class="ipt">
				<?php echo $form->textField($model,'first_name', array('class'=>'span12')); ?>
				<?php echo $form->error($model,'first_name'); ?>
			</div>
		</div>
		<div class="span5">
			<div class="lbl"><?php echo $form->labelEx($model,'last_name'); ?></div>
			<div class="ipt">
				<?php echo $form->textField($model,'last_name', array('class'=>'span12')); ?>
				<?php echo $form->error($model,'last_name'); ?>
			</div>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'email'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'email', array('class'=>'span12')); ?>
			<?php echo $form->error($model,'email'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'phone'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'phone', array('class'=>'span12')); ?>
			<?php echo $form->error($model,'phone'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'address'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'address', array('class'=>'span12')); ?>
			<?php echo $form->error($model,'address'); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'city'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'city', array('class'=>'span6')); ?>
		</div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'category_key'); ?></div>
		<div class="ipt">
			<?php echo $form->dropDownList($model, 'category_key', $categories, array('empty'=>'')); ?>
			<?php echo $form->error($model,'category_key'); ?>
		</div>
		<div class="eg"><?php echo BUtils::T('category_business_eg'); ?></div>
	</div>
	<div class="block">
		<div class="lbl"><?php echo $form->labelEx($model,'url_site'); ?></div>
		<div class="ipt">
			<?php echo $form->textField($model,'url_site', array('class'=>'span12')); ?>
		</div>
	</div>
	<div class="block text-right">
		<div class="ipt clearfix">
			<?php echo CHtml::submitButton(BUtils::T('confirm_btn'), array('class' => 'btn btn-large btn-primary span4')); ?>
		</div>
	</div>
<?php
//echo $form->hiddenField($model,'latitude');
//echo $form->hiddenField($model,'longitude');
echo $form->hiddenField($model,'zip_code');
echo $form->hiddenField($model,'country_code');
?>
</div><!-- end of .fields -->
</div><!-- end of .fieldswrap -->

	<div class="margin actions">
		<?php echo CHtml::link('<span>'.BUtils::T('have_account_already_lbl').'</span>', Yii::app()->user->loginUrl, array('class' => '')); ?>
	</div>

<?php
	$this->endWidget();
}
?>

		</div><!-- end of <div class="biz-form"> -->
	</div>
</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$("#ContactForm_address").geocomplete({
		details: '.geo-info', location: []
	}).bind("geocode:result", function(event, result){
		setLocationValues(result);
	});
});
function setLocationValues(loc) {
	var lat = loc.geometry.location.lat();
	var lng = loc.geometry.location.lng();
	var locArray = loc.formatted_address.split(', ');
	if (locArray.length > 2) {
		//console.log(locArray);
		var street_number, address, postal_code, city, country, country_code;
		$.map(loc.address_components, function(obj) {
			switch (obj.types[0]) {
				case 'postal_code':
					postal_code = obj.long_name;
					break;
				case 'country':
					country = obj.long_name;
					country_code = obj.short_name;
					break;
				case 'locality':
				case 'administrative_area_level_3':
					if (city == null) city = obj.long_name;
					break;
				case 'administrative_area_level_1':
					if (city == null) city = obj.long_name;
					break;
				case 'route':
					address = obj.long_name;
					break;
				case 'street_number':
					street_number = obj.long_name;
					break;
			}
		});
		if (country_code != null) {
			$('#ContactForm_latitude').val(lat);
			$('#ContactForm_longitude').val(lng);
			$("#ContactForm_postcode").val(postal_code);
			$("#ContactForm_city").val(city);
			$("#ContactForm_country_code").val(country_code);
		}
	}
}
</script>
<?php
$langcode = Yii::app()->language;
if ($langcode == 'zh_cn') $langcode = 'en';
?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&language=<?php echo $langcode; ?>"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/labs/jquery.geocomplete.min.js"></script>